package com.yanfan.point.service.impl;


import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yanfan.accessControl.service.IIbmsAccessControlDeviceService;
import com.yanfan.common.utils.StringUtils;
import com.yanfan.energy.service.IIbmsEnergyDeviceService;
import com.yanfan.ibms.common.vo.DeviceVo;
import com.yanfan.system.util.DeptTypeUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yanfan.point.mapper.IbmsDeviceTypeMapper;
import com.yanfan.point.domain.IbmsDeviceType;
import com.yanfan.point.service.IIbmsDeviceTypeService;

/**
 * 设备类型Service业务层处理
 *
 * @author genluo
 * @date 2024-10-10
 */
@Service
public class IbmsDeviceTypeServiceImpl extends ServiceImpl<IbmsDeviceTypeMapper,
        IbmsDeviceType> implements IIbmsDeviceTypeService {
    @Autowired
    private IbmsDeviceTypeMapper ibmsDeviceTypeMapper;
    @Autowired
    private DeptTypeUtils deptTypeUtils;
    @Autowired
    private IIbmsEnergyDeviceService ibmsEnergyDeviceService;

    @Autowired
    private IIbmsAccessControlDeviceService iIbmsAccessControlDeviceService;


    /**
     * 查询设备类型列表
     *
     * @param ibmsDeviceType 设备类型
     * @return 设备类型
     */
    @Override
    public List<IbmsDeviceType> queryPageList(IbmsDeviceType ibmsDeviceType) {
        LambdaQueryWrapper<IbmsDeviceType> lqw = buildQueryWrapper(ibmsDeviceType);
        return ibmsDeviceTypeMapper.selectList(lqw);
        //连表查询可用该方法，在此方法SQL语句上进行扩展
        //return ibmsDeviceTypeMapper.queryPageList(ibmsDeviceType);
    }

    @Override
    public List<IbmsDeviceType> getDeviceType(Long id) {
        return ibmsDeviceTypeMapper.getDeviceType(id);
    }

    @Override
    public List<DeviceVo> getDeviceInfor(String deviceType, String groupName) {
        String deptType = deptTypeUtils.deptType();
        List<DeviceVo>listType = null;
        if (deptType.equals("园区")){
            deptType = null;
        }


        if(groupName.equals("楼宇自控")){


        }else if(groupName.equals("视频监控")){

        }else if(groupName.equals("停车场")){

        }else if(groupName.equals("门禁管理")){
            List<DeviceVo> list = iIbmsAccessControlDeviceService.selectByDeviceType(deptType);
            listType=list;

        }else if(groupName.equals("周界报警")){

        }else if(groupName.equals("能耗管理")){
            List<DeviceVo> list = ibmsEnergyDeviceService.selectByDeviceType(deviceType,deptType);
            listType=list;
        }
        return listType;
    }


    /**
    * 分页查询条件
    * @return
    */
    private LambdaQueryWrapper<IbmsDeviceType> buildQueryWrapper(IbmsDeviceType bo) {
        LambdaQueryWrapper<IbmsDeviceType> lqw = Wrappers.lambdaQuery();
        lqw.eq(StringUtils.isNotBlank(bo.getDeviceType()), IbmsDeviceType::getDeviceType, bo.getDeviceType());
        lqw.eq(bo.getGroupId() != null, IbmsDeviceType::getGroupId, bo.getGroupId());
        lqw.like(StringUtils.isNotBlank(bo.getGroupName()), IbmsDeviceType::getGroupName, bo.getGroupName());
        lqw.eq(StringUtils.isNotBlank(bo.getIcon()), IbmsDeviceType::getIcon, bo.getIcon());
        return lqw;
    }



}
